//
//  HomePageCollectionViewCell.m
//  YHYRealx
//
//  Created by yanghuiyan on 16/4/19.
//  Copyright © 2016年 yanghuiyan. All rights reserved.
//

#import "HomePageCollectionViewCell.h"
#import "HomePageDataModel.h"
@implementation HomePageCollectionViewCell

- (void)dealloc {
    
    _homeTableView.delegate = nil;
    _homeTableView.dataSource = nil;
    
    [_homeTableView release];
    [_dataSource release];
    
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.dataSource = [NSMutableArray array];
        
        self.backgroundColor = [UIColor colorWithRed:248/255.0 green:249/ 255.0 blue:240/255.0 alpha:1];
        
        _homeTableView.backgroundColor = [UIColor clearColor];
        
        self.homeTableView = [[YHYBaseTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        [_homeTableView registerClass:[HomePageTableViewCell class] forCellReuseIdentifier:@"homeT"];
        _homeTableView.backgroundColor = [UIColor colorWithRed:248 / 255.0 green:249 / 255.0 blue:240 / 255.0 alpha:1];
        _homeTableView.delegate = self;
        _homeTableView.dataSource = self;
        
        
        [self.contentView addSubview:_homeTableView];
        
        [_homeTableView release];
        
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    
    _homeTableView.frame = INYHY;
    

    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    // 计算文字高度 调用cell类方法
    _cellHeight = [HomePageTableViewCell heightWithText:_dataModel.hp_content];
    
    // 返回计算后的cell高度
    return _cellHeight + 350;

    
}


- (void)setDataModel:(HomePageDataModel *)dataModel {
    if (_dataModel != dataModel) {
        [_dataModel release];
        _dataModel = [dataModel retain];
    }
    [_homeTableView reloadData];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    HomePageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"homeT"];
//    cell.delegate = self;
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    cell.layer.cornerRadius = 5;
    cell.layer.masksToBounds = YES;
    cell.layer.borderWidth = 2;
    cell.layer.borderColor = [UIColor lightGrayColor].CGColor;
    
    cell.dataModel = _dataModel;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [self.homeTableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

//- (void)shareAction {
//    [self.delegate favoriteAction];
//}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
